package com.scaffold.myproject.common;

import lombok.Data;

/**
 * 操作提示类
 */
@Data
public class CodeMsg {

    /******************** 通用错误码 ********************/
    public static CodeMsg SUCCESS = new CodeMsg(true, 10000, "success");
    public static CodeMsg SERVER_ERROR = new CodeMsg(false, 10001, "系统服务异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(false, 10002, "参数校验异常");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(false, 10003, "请求非法");
    public static CodeMsg ACCESS_LIMIT_REACHED = new CodeMsg(false, 10004, "访问太频繁");
    public static CodeMsg PARAMETER_ERROR = new CodeMsg(false, 10005, "参数异常,%");
    public static CodeMsg REMOTE_REQUEST_ERROR = new CodeMsg(false, 10006, "远程调用失败");
    public static CodeMsg UNKNOWN_ERROR = new CodeMsg(false, 99998, "未知异常");
    public static CodeMsg SEARCH_DATA_EMPTY = new CodeMsg(false, 99999, "暂未查到相关信息");

    /**
     * 是否成功, true或false
     */
    private boolean success;

    /**
     * 操作编码
     */
    private int code;

    /**
     * 操作提示
     */
    private String msg;

    public CodeMsg(boolean success, int code, String msg) {
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String msg = String.format(this.msg, args);
        return new CodeMsg(false, code, msg);
    }
}